<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>全名(侦听属性)</title>
</head>

<body>
    <h1>全名(侦听属性)</h1>
    <p style="color: gray;">
    app.firstName = "Tom"
    app.lastName = "Jack"
    </p>
    <div>
        <a href="/">回目录</a>
    </div>
    <hr>
    <div id="app">
        <div>First Name : {{ firstName }}</div>
        <div>Last Name : {{ lastName }}</div>
        <div>Full Name  : {{ fullName }}</div>
    </div>
    <script src="/node_modules/vue/dist/vue.js"></script>
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                firstName: "Vue",
                lastName: "js",
                fullName: null,
            },
            created: function() {
                this.updateFullname(this.firstName, this.lastName);
            },
            watch: {
                firstName : function(newValue) {
                    this.updateFullname(newValue, this.lastName);
                },
                lastName : function(newValue) {
                    this.updateFullname(this.firstName, newValue);
                },
            },
            methods: {
                updateFullname : function(firstName, lastName) {
                    this.fullName =  firstName + "." + lastName;
                } 
            }
        });
    </script>
</body>

</html>